﻿// *****************************************************************************
// **                   Ladenius MediaCenter TVSeries                         **
// ** ----------------------------------------------------------------------- **
// ** (c) 2008 by Jurjen Ladenius                                             **
// *****************************************************************************

#region Using directives
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ladenius.TheTVDB;
using Ladenius.TheTVDB.Entities;
#endregion


namespace Ladenius.Series.Configuration.WinClient {
    /// <summary>
    /// Used for finding TVDB records
    /// </summary>
    internal class TVDB {
        /// <summary>
        /// Gets the TVDB_SeriesID.
        /// </summary>
        /// <param name="seriesName">Name of the series.</param>
        /// <returns></returns>
        internal TheTVDB.Entities.Series GetTVDBSeries(string seriesName, string languageAbbreviation) {

            TheTVDBManager manager = new TheTVDBManager();

            // Retrieve language
            Language language = manager.GetLanguageByAbbreviation(languageAbbreviation);

            // Find series 
            List<TheTVDB.Entities.Series> foundSeries = manager.FindSeries(seriesName);

            // If more than one, or zero, found, determine manually
            TheTVDB.Entities.Series series = null;
            if (foundSeries.Count != 1) {

                Forms.FrmTVDBSeries frmTVDBSeries = new Forms.FrmTVDBSeries(seriesName, language);
                frmTVDBSeries.ShowDialog();
                series = frmTVDBSeries.SelectedSeries;
            } else {
                series = foundSeries[0];
            }

            return series;
        }

        internal Ladenius.TheTVDB.Entities.Series GetTVDBSeries(int tvdb_seriesID, string seriesName, string languageAbbreviation) {

            // If no ID, then use other method
            if (tvdb_seriesID < 0) {
                return GetTVDBSeries(seriesName, languageAbbreviation);
            }

            TheTVDBManager manager = new TheTVDBManager();

            // Retrieve language
            Language language = manager.GetLanguageByAbbreviation(languageAbbreviation);

            // Find series
            return manager.GetSeriesByID(tvdb_seriesID, language);
        }
    }
}
